package com.congee02.bt.dfs.top2bottom;

import com.congee02.bt.TreeNode;

public class IsUnivalTree {

    int rootValue;
    public boolean isUnivalTree(TreeNode root) {
        rootValue = root.val;
        return help(root);
    }

    private boolean help(TreeNode root) {
        if (root == null) {
            return true;
        }
        if (root.val != rootValue) {
            return false;
        }
        return help(root.left) && help(root.right);
    }

}
